class Solution(object):
    def compareVersion(self, version1, version2):
        """
        :type version1: str
        :type version2: str
        :rtype: int
        """
        ver1 = [int(i) for i in version1.split('.')]
        ver2 = [int(i) for i in version2.split('.')]

        while len(ver1)!=0 and ver1[-1]==0: ver1.pop()
        while len(ver2)!=0 and ver2[-1]==0: ver2.pop()

        for i in range(min(len(ver1), len(ver2))):
            if ver1[i]>ver2[i]: return 1
            elif ver1[i]<ver2[i]: return -1
        if len(ver1)>len(ver2): return 1
        elif len(ver1)<len(ver2): return -1
        else: return 0